/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import other.FileInfo;

/**
 *
 * @author Sam
 */
public class FileTab extends JScrollPane {

    public class FileModel extends AbstractTableModel {

        private final List<FileInfo> files = new ArrayList<>();
        private final String[] titre = {"Name", "Type", "Size", "Path"};
        
        public List<FileInfo> getfiles(){return files;}
        
        public FileModel() {
            super();
        }
        
        public void clear() {
             files.clear();}

        @Override
        public int getRowCount() {
            return files.size();
        }

        @Override
        public int getColumnCount() {
            return titre.length;
        }

        @Override
        public String getColumnName(int columnIndex) {
            return titre[columnIndex];
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            if (rowIndex < files.size()) {
                switch (columnIndex) {
                    case 0:
                        return files.get(rowIndex).getname();
                    case 1:
                        return files.get(rowIndex).gettype();
                    case 2:
                        return files.get(rowIndex).getsize();
                    case 3:
                        return files.get(rowIndex).getpath();
                    default:
                        return null;
                }
            } else {
                return null;
            }
        }// */

        public void addFile(FileInfo user) {
            int i=0;
            for (FileInfo user1 : files) {
            if (!(user1.getpath().equals(user.getpath()))) {i++;}}
            if(i==(files.size())){
            files.add(user);
            fireTableRowsInserted(files.size() - 1, files.size() - 1);
            }       
        }
        
        public void removeFile(String path) {
            for (FileInfo user : files) {
                if (user.getpath().equals(path)) {
                    files.remove(user);
                    return;
                }
            }
        }
    }

    public FileTab() {
        jTable1.setModel(mymodel);
        this.setViewportView(jTable1);

    }
    JTable jTable1 = new javax.swing.JTable();
        FileTab.FileModel mymodel = new FileTab.FileModel();

}